package com.example.exam.controller;

import com.example.exam.entity.Message;
import com.example.exam.service.MessageService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Message)表控制层
 *
 * @author makejava
 * @since 2021-09-07 16:33:39
 */
@RestController
@RequestMapping("message")
public class MessageController {
    /**
     * 服务对象
     */
    @Resource
    private MessageService messageService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public Message selectOne(Integer id) {
        return this.messageService.queryById(id);
    }

    @RequestMapping("/insertMess")
    public int insertOne(String s) {
        if (s == null) {
            return 0;
        }
        Message message = new Message();
        message.setMessage(s);
        Message insert = this.messageService.insert(message);
        return insert == null ? 0 : 1;
    }

    @RequestMapping("/selectAll")
    public List<Message> selectAll() {
        return messageService.queryAll();
    }
}